package ru.niir.goodfil.utils;

public class Transliter {
    private final static String alpha = new String("абвгдеёжзиыйклмнопрстуфхцчшщьэюя");
    private final static String[] _alpha = {"a", "b", "v", "g", "d", "e", "yo", "g", "z", "i", "y", "i", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "tz", "ch", "sh", "sh", "'", "e", "yu", "ya"};

    public static String translit(String input) {
        if (input == null) return "";

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            boolean isUppercase = Character.isUpperCase(c);
            c = Character.toLowerCase(c);

            int index = alpha.indexOf(c);
            if (index == -1) {
                if (isUppercase) {
                    sb.append(Character.toUpperCase(c));
                } else {
                    sb.append(c);
                }
            } else {
                if (isUppercase) {
                    sb.append(_alpha[index].toUpperCase());
                } else {
                    sb.append(_alpha[index]);
                }

            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println("> " + Transliter.translit("Привет, Трансформеры"));
    }

}
